/*
|-----------------------------------------------------------------------------|
| Overall ANTLR Grammar File Structure                                        |
|-----------------------------------------------------------------------------|
| «grammarType» grammar name;
|   «optionsSpec»     = options { ... }
|   «tokensSpec»      = tokens { ... }
|   «attributeScopes» = «@action-scope-name::action-name» { ... }
|   «actions»
|   // rules
|   rule1 : ... ;
|   rule2 : ... ;
|   ...
|_____________________________________________________________________________|
|   «grammarType»         = ( lexer | parser | tree | <empty> )
|   «optionsSpec»         = options { ... }
|   «tokensSpec»          = tokens { ... }
|   «attributeScopes»     = 
|   «actions»             = @«action-scope-name»::«action-name» { ... }
|    «action-scope-name» = ( lexer | parser | tree | <empty> = parser )
|    «action-name»       = ( header | members | rulecatch | synpredgate )
|-----------------------------------------------------------------------------|
*/
lexer grammar XMLLexer;

  options {
    language = Java;
  }// options
  
  @lexer::header {
    package pl.p06.antlr3;
  }//header
  @lexer::members {
    boolean tagMode = false;
  }// members

//= Lexer Rules XML ==========================================================|
// Referencia: http://www.antlr.org/wiki/display/ANTLR3/1.+Lexer
  fragment NewLine
    : '\r'? '\n'
    ;

  fragment Digit
    : '0'..'9'
    ;

  fragment Letter
    : 'a'..'z'
    | 'A'..'Z'
    ;

	TagStartOpen
	  : '<' { tagMode = true; }
	  ;

	TagEndOpen
	  : '</' { tagMode = true; }
	  ;

	TagClose
	  : { tagMode }? => '>' { tagMode = false; }
	  ;

  Identifier
      : { tagMode }? => Letter(Letter|Digit)+
      ;

	AttributeAssing
	  : { tagMode }? => '=' ;

	AttributeValue
	  : { tagMode }? =>
		    ( '"'  (options { greedy=false; } : (~'"') )* '"'
		    | '\'' (options { greedy=false; } : (~'\''))* '\''
		    )
	  ;

  PCDATA
    : { !tagMode }? => (~'<')+ ;

	Space
	  : (' '|'\t'|'\u000C'|NewLine) { $channel=HIDDEN; skip(); };

	Comment
	  : '<!--' (options {greedy=false;} : ( Comment | . ))* '-->' { $channel=HIDDEN; skip(); }
	  ;
	/* 
	//Reglas explícitas
	InitLibrary   : "<biblioteca";
	InitBook      : "<libro";
	InitTitle     : "<titulo";
	InitAuthor    : "<autor";
	InitEditorial : "<editorial";
	EndLibrary    : "</biblioteca";
	EndBook       : "</libro";
	EndTitle      : "</titulo";
	EndAuthor     : "</autor";
	EndEditorial  : "</editorial";
	*/
